#pragma once
#include <io.h>
#include <vector>
#include <string>
namespace xpam
{
    class filesystem
    {
    public:
        static void directories(const std::string & path, std::vector<std::string> & dirslist, int lvl = 255)
        {
            dirslist.push_back(path);
            _finddata_t fileinfo;
            intptr_t find_ptr = _findfirst((path + "\\*").c_str(), &fileinfo);
            if (find_ptr == -1) return;
            do 
            {
                std::string filename = fileinfo.name;
                if (filename != "." && filename != "..")
                {
                    if (fileinfo.attrib & _A_SUBDIR)
                    {
                        if (lvl > 0)
                            directories(path + "\\" + filename, dirslist, lvl - 1);
                        else
                            dirslist.push_back(path + "\\" + filename);
                    }
                }
            } while(_findnext(find_ptr, &fileinfo) == 0);
            _findclose(find_ptr);
        }
        static void files(const std::string & path, const std::string & mask, std::vector<std::string> & fileslist)
        {
            _finddata_t fileinfo;
            intptr_t find_ptr = _findfirst((path + "\\" + mask).c_str(), &fileinfo);
            if (find_ptr == -1) return;
            do 
            {
                std::string filename = fileinfo.name;
                if (filename != "." && filename != "..")
                {
                    if (!(fileinfo.attrib & _A_SUBDIR))
                    {
                        fileslist.push_back(path + "\\" + filename);
                    }
                }
            } while(_findnext(find_ptr, &fileinfo) == 0);
            _findclose(find_ptr);
        }
    };
}